package org.tpdata.api.singlequality.hospitalqc;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import common.Data;
import common.Login;
import common.RunCaseJson;
import exceptions.TestNGRetry;
import io.qameta.allure.Feature;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import utils.GetFileMess;

@Feature("获取实时质控评价的reportdatas数据")
public class GetReport  {
    Logger log = Logger.getLogger(GetReport.class);
    public static final String timestamp = String.valueOf(System.currentTimeMillis());
    @BeforeClass
    public void envSetUp() {
        try {
            String system = "env.properties";    //环境由filter配置
            RestAssured.baseURI = new GetFileMess().getValue("baseURI", system);
            RestAssured.basePath = new GetFileMess().getValue("basePath", system);
            RestAssured.port = Integer.parseInt(new GetFileMess().getValue("port", system));
            System.out.println(RestAssured.basePath);
        } catch ( ConfigurationException e) {
            e.printStackTrace();
        }
    }
    @Parameters({"diseaseCode","reportNos","uri"})
    @Test(retryAnalyzer = TestNGRetry.class,description = "获取实时质控评价，待处理，我发起的总数")
    public void GetHistoryList(String diseaseCode,String reportNos,String uri) {
        Data data= Login.login();
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("create_id", data.getUserId());
        json.put("authName",data.getUserName());
        json.put("medCode", diseaseCode);     // 病种
        json.put("reportNos", reportNos);     //报告号码
json.put("timestamp",timestamp);
json.put("org_ids",true);
        Response response = RunCaseJson.runCase(json, "get", uri);
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        JSONObject obj = JSONObject.parseObject(jsonStr);
        JSONArray js=obj.getJSONArray("responseData");


String rt_create=obj.getString("rt_create");      //我发起的
//String rt_pending=RD.getString("rt_pending");       //待处理
        Assert.assertNotEquals(rt_create,"");
//        Assert.assertNotEquals(rt_pending,"");
    }
}
